package com.zyf.school.manager.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyf.school.manager.dao.DepartmentDao;
import com.zyf.school.manager.domain.Department;
import com.zyf.school.manager.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentDao,Department> implements DepartmentService{

    @Autowired
    private DepartmentDao departmentDao;

    List<Department> list;

    @Override
    public Department queryById(int id) {
        return departmentDao.selectById(id);
    }


    @Override
    public List<Department> queryAll() {
        list = departmentDao.queryParent();
        list = setList(list);
        return list;
    }

    @Override
    public List<Department> queryParent(int id) {
        list = departmentDao.queryChildren(id);
        list = setList(list);
        return list;
    }

    //遍历查询
    public List<Department> setList(List<Department> dlist){
        for (int i=0; i<dlist.size(); i++){
            List<Department> al = departmentDao.queryChildren(dlist.get(i).getId());
            dlist.get(i).setList(al);
            setList(al);
        }
        return dlist;
    }
}
